package com.im.it.utils;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * R 结果统一返回
 *
 * @author new
 * @date 2023/7/28 16:38
 */
@Data
@Accessors(chain = true)
public class R<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;

    public static <S> R success(S data) {
        return new R()
                .setCode(Codes.SUCC.getCode())
                .setMsg(Codes.SUCC.getMsg())
                .setData(data);
    }

    public static R success() {
        return new R()
                .setCode(Codes.SUCC.getCode())
                .setMsg(Codes.SUCC.getMsg());
    }

    public static <S> R erro(Codes codes, S data) {
        return new R()
                .setCode(codes.getCode())
                .setMsg(codes.getMsg())
                .setData(data);
    }

    public static <S> R erro(Codes codes) {
        return erro(codes, null);
    }
}
